package com.chinasofti.zbest.web;


import com.chinasofti.zbest.dao.model.User;
import com.chinasofti.zbest.dao.model.UserAddr;
import com.chinasofti.zbest.service.IUserAddrService;
import com.chinasofti.zbest.service.IUserService;
import com.chinasofti.zbest.service.info.UserAddrInfo;
import com.chinasofti.zbest.service.info.UserModifyInformationInfo;
import com.chinasofti.zbest.web.form.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;


import javax.servlet.http.HttpSession;
import java.time.LocalDateTime;
import java.util.Date;
import java.util.List;

/**
 * <p>
 * 用户 前端控制器
 * </p>
 *
 * @author zbest
 * @since 2019-05-28
 */
@RequestMapping("/user")
@Controller
@Slf4j
public class UserController extends BaseController {

    @Autowired
    private IUserService iUserService;



    /**
     * 进入个人中心页面
     *
     * @param session
     * @return
     */
    @RequestMapping("/myPersonCenter")
    public String personCenter(HttpSession session, ModelMap modelMap) {
        log.info("mypersoncenter,121");
        User user = (User) session.getAttribute("user");
        modelMap.addAttribute("userinformation", user);
        return "user/mygxin";
    }

    /**
     * 进入修改个人信息界面
     *
     * @param session
     * @param modelMap
     * @return
     */
    @RequestMapping("midifyGRXinXi")
    public String midifyGRXinXi(HttpSession session, ModelMap modelMap) {

        log.info("信息修改页面");
        User user = (User) session.getAttribute("user");
        modelMap.addAttribute("user", user);
        return "user/mygrxx";
    }

    /**
     * 进入修改个人信息方法
     *
     * @param session
     * @param modifyuser
     * @param modelMap
     * @return
     */
    @RequestMapping("revampGRXinXi")
    public String revampGRXinXi(HttpSession session, ModifyUserInformationForm modifyuser, ModelMap modelMap) {

        log.info("进入此页面  方法  " + modifyuser);
        UserModifyInformationInfo modifyInfo=new UserModifyInformationInfo();
        BeanUtils.copyProperties(modifyuser, modifyInfo);
        log.info("{}",modifyInfo);
        try {
            iUserService.updateUserInformation(modifyInfo);
        } catch (RuntimeException e) {
            log.info("修改个人信息出错");
            e.printStackTrace();
        }
        User user = iUserService.getById(modifyuser.getUserId());
//        session.setAttribute("user", user);
        modelMap.addAttribute("user", user);

        return "user/mygrxx";
    }



}








